package com.list;

public class Test2 {
    public static ListNode removeNthFromEnd(ListNode head, int n) {
       ListNode p1=head;
        for (int i = 0; i < n; i++) {
            p1=p1.next;
        }
        ListNode p2=head;
        while (p2!=null){
            p1=p1.next;
            p2=p2.next;
        }
        p2.next=p2.next.next;
        return p2;
    }
    //. 两两交换链表中的节点
    public ListNode swapPairs(ListNode head){
        if (head==null||head.next==null){
            return head;
        }
        ListNode next=head.next;
        head.next=swapPairs(next.next);
        next.next=head;
        return next;
    }
}
